package com.example.baselibrary.db.table;

import android.text.TextUtils;

import com.example.baselibrary.bean.UserManager;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;


/**
 * 搜索记录表
 *
 * @author Zml
 * @date 2018/5/15.
 */
@DatabaseTable(tableName = "SearchHistoryTable")
public class SearchHistoryTable {
    /**
     * 用户 Id (区分是哪个用户的搜索记录)
     */
    @DatabaseField(columnName = "userId")
    private String userId = UserManager.Companion.getUserId();
    /**
     * 关键字or人名/群名
     */
    @DatabaseField(columnName = "keyword")
    public String keyword = "";
    /**
     * 人/群Id
     */
    @DatabaseField(columnName = "keywordId")
    public String keywordId = "";
    /**
     * 头像
     */
    @DatabaseField(columnName = "avatar")
    public String avatar = "";
    /**
     * 搜索类型
     */
    @DatabaseField(columnName = "searchType")
    public String searchType = "";
    /**
     * 保存数据的时间戳
     */
    @DatabaseField(columnName = "timestamp", id = true)
    public String timestamp = String.valueOf(System.currentTimeMillis());

    public SearchHistoryTable(String keyword, String keywordId, String avatar, String searchType) {
        this.keyword = null == keyword ? "" : keyword;
        this.keywordId = null == keywordId ? "" : keywordId;
        this.avatar = null == avatar ? "" : avatar;
        this.searchType = null == searchType ? "" : searchType;
    }

    public SearchHistoryTable() {
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof SearchHistoryTable) {
            SearchHistoryTable table = (SearchHistoryTable) obj;
            if (TextUtils.equals(table.keyword, keyword) && TextUtils.equals(table.keywordId, keywordId) &&
                    TextUtils.equals(table.avatar, avatar) && TextUtils.equals(table.searchType, searchType)) {
                return true;
            }
        }
        return super.equals(obj);
    }

}
